Kotlin Koans 27 Group By

目次

Group By (Playground)

Description

Implement Shop.groupCustomersByCity() using groupBy.

groupBy を使用して、Shop.groupCustomersByCity() を実装してください。

val result = listOf("a", "b", "ba", "ccc", "ad").groupBy { it.length() }
result == mapOf(1 to listOf("a", "b"), 2 to listOf("ba", "ad"), 3 to listOf("ccc"))

Code

// Return a map of the customers living in each city
fun Shop.groupCustomersByCity(): Map<City, List<Customer>> = customers.groupBy { it.city }

Memo

← Posts